import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path'; // 导入path模块

// https://vitejs.dev/config/
export default defineConfig({
  // base: './',
  plugins: [
    react(), // 按需引入antd样式
    ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'), // 将@指向src目录
      // 可以继续添加其他别名
      // 例如：'@components': path.resolve(__dirname, './src/components')
    }
  },
  build: {
    rollupOptions: {
      output: {
        manualChunks: {
          'react-core': ['react', 'react-dom', 'react-router-dom'],
          // 将 antd 拆分为多个更小的 chunks
          'antd-core': [
            'antd/es/layout',
            'antd/es/button',
            'antd/es/form',
            'antd/es/input'
          ],
          
          // 按功能模块进一步拆分
          'antd-data-display': [
            'antd/es/table',
            'antd/es/card',
            'antd/es/descriptions'
          ],
          
          'antd-data-input': [
            'antd/es/select',
            'antd/es/date-picker',
            'antd/es/time-picker'
          ],
          
          // 将图标库单独拆分
          'antd-icons': ['@ant-design/icons'],
          
          // 其他第三方依赖
          'util-vendor': ['axios']
        }
      },
    },
    chunkSizeWarningLimit: 1000,
    // 开启 terser 高级压缩
    minify: 'terser',
    terserOptions: {
      compress: {
        drop_console: true,     
        drop_debugger: true,
        pure_funcs: ['console.log'],
      },
      format: {
        comments: false
      }
    },
  },
  server: {
    port: '8087',
    host: "0.0.0.0",
    proxy: {
      '/app': {
        target: 'http://192.168.1.32:8087',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/app/, '/app'),
      },
    }
  }
});